package mango.web.client.admin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mango.web.client.C;
import mango.web.client.View;

import com.axeiya.gwtckeditor.client.CKConfig;
import com.axeiya.gwtckeditor.client.CKConfig.TOOLBAR_OPTIONS;
import com.axeiya.gwtckeditor.client.CKEditor;
import com.axeiya.gwtckeditor.client.Toolbar;
import com.axeiya.gwtckeditor.client.ToolbarLine;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;

public class AdminDbView extends View {
	protected static AdminDbView adminDbView;

	public static AdminDbView get(String key) {
		if ("".equals(key)) {
			if (AdminDbView.adminDbView == null) AdminDbView.adminDbView = new AdminDbView().init();
			return AdminDbView.adminDbView;
		}
		return null;
	}

	public FlexTable tableVarietyHeader;
	public FlexTable tableVariety;
	public FlexTable tableRegionHeader;
	public FlexTable tableRegion;
	public FlexTable tableTemperatureHeader;
	public HTML htmlTemperature;
	public HTML htmlHelp;
	public FlexTable tableLookupTHeader;
	public FlexTable tableLookupT;
	public FlexTable tableMemberPropertyHeader;
	public FlexTable tableMemberProperty;
	public TextBox orchardEmailSubject;
	public CKEditor orchardEmailContent;
	//public HTML orchardEmailContentHTML;
	public ListBox emailContentListBox;
	public HTML htmlMailSend;
	public ListBox emailListTypeBox;

	public TextBox smsSubject;
	public TextArea smsContent;
	public ListBox smsContentListBox;
	public HTML htmlWords;

	public FlexTable tableOrchardEmailHeader;
	public FlexTable tableOrchardEmail;

	public int idListOrchardEmail = 0;

	public HTML htmlTotalTree;
	public FlexTable tableTree;

	public FlexTable tableFlowerHeader;
	public FlexTable tableFlower;

	public FlexTable tableSummaryHeader;
	public FlexTable tableSummary;

	public FlexTable tableRegionSelect;
	//public OrchardVo selectedOrchard;
	//public HTML orchardHTML;
	//public FlowerChart flowerChart;
	public FlowerChart flowerChart;
	public FlowerChart flowerChart2;

	public FlexTable tableSum1Header;
	public FlexTable tableSum1;

	public AdminDbView init() {
		this.panel.setSize("1000px", "570px");

		FlexTable table;
		AbsolutePanel panel;
		Label label;
		HTML html;
		TextBox textBox;
		CheckBox checkBox;
		ListBox listBox;
		RadioButton radioButton;
		TextArea textArea;
		Button button;
		int top;
		int left;

		panel = new AbsolutePanel();
		panel.setSize("1000px", "100px");
		this.panel.add(panel, 0, 0);

		left = 967;

		html = new HTML("<img src='image/exit.png' style='cursor:pointer'/>");
		panel.add(html, left, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				dialogBox.hide();
			}
		});

		//TODO: Variety
		int width = 980;
		int height = 500;

		TabPanel tab;
		AbsolutePanel tabPanel;

		tab = new TabPanel();

		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		this.tableVarietyHeader = new FlexTable();

		html = new HTML("<b><u>varietyId</u></b>");
		html.setWidth("80px");
		this.tableVarietyHeader.setWidget(0, 0, html);

		html = new HTML("<b><u>varietyName</u></b>");
		html.setWidth("200px");
		this.tableVarietyHeader.setWidget(0, 1, html);

		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewVarietyAdd(varietyListCallback);
			}
		});
		this.tableVarietyHeader.setWidget(0, 2, html);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				C.adminViewS.viewVarietySave(getVarietyList(), varietyListCallback);
			}
		});
		this.tableVarietyHeader.setWidget(0, 3, html);
		tabPanel.add(this.tableVarietyHeader, left, top);

		AbsolutePanel tablePanel = new AbsolutePanel();
		this.tableVariety = new FlexTable();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 14 + "px");
		tablePanel.add(this.tableVariety, 0, 2);
		tabPanel.add(tablePanel, left, top + 16);

		tab.add(tabPanel, "Variety");

		//TODO: Region
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		this.tableRegionHeader = new FlexTable();

		html = new HTML("<b><u>regionId</u></b>");
		html.setWidth("60px");
		this.tableRegionHeader.setWidget(0, 0, html);

		html = new HTML("<b><u>regionName</u></b>");
		html.setWidth("150px");
		this.tableRegionHeader.setWidget(0, 1, html);

		html = new HTML("<b><u>postCodes</u></b>");
		html.setWidth("250px");
		this.tableRegionHeader.setWidget(0, 2, html);

		html = new HTML("<b><u>subRegions</u></b>");
		html.setWidth("400px");
		this.tableRegionHeader.setWidget(0, 3, html);

		html = new HTML("<b><u>state</u></b>");
		html.setWidth("60px");
		this.tableRegionHeader.setWidget(0, 4, html);

		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("add new record?")) return;
				C.adminViewS.viewRegionAdd(regionListCallback);
			}
		});
		this.tableRegionHeader.setWidget(0, 5, html);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				C.adminViewS.viewRegionSave(getRegionList(), regionListCallback);
			}
		});
		this.tableRegionHeader.setWidget(0, 6, html);
		tabPanel.add(this.tableRegionHeader, left, top);

		tablePanel = new AbsolutePanel();
		this.tableRegion = new FlexTable();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 14 + "px");
		tablePanel.add(this.tableRegion, 0, 2);
		tabPanel.add(tablePanel, left, top + 16);

		tab.add(tabPanel, "Region");

		//TODO: Financial Member
		tabPanel = new AbsolutePanel();
		tabPanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tabPanel.setSize("980px", "500px");

		top = 0;
		left = 0;
		this.tableMemberPropertyHeader = new FlexTable();
		tabPanel.add(this.tableMemberPropertyHeader, left, top);

		html = new HTML("<b><u></u></b>");
		html.setWidth("80px");
		this.tableMemberPropertyHeader.setWidget(0, 0, html);

		html = new HTML("<b><u></u></b>");
		html.setWidth("200px");
		this.tableMemberPropertyHeader.setWidget(0, 1, html);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				C.adminViewS.saveMemberPropertyVo(getMemberPropertyVo(), memberPropertyCallback);
			}
		});
		this.tableMemberPropertyHeader.setWidget(0, 2, html);

		tablePanel = new AbsolutePanel();
		this.tableMemberProperty = new FlexTable();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 20 + "px", height - 30 + "px");
		tablePanel.add(this.tableMemberProperty, 0, 2);
		tabPanel.add(tablePanel, left, top + 16);

		tab.add(tabPanel, "Financial Member");

		this.panel.add(tab, 0, 30);

		//TODO: Orchard Email
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");
		/*
		top = 0;
		left = 0;
		html = new HTML("<b>Subject</b>");
		tabPanel.add(html, left, top);
		*/

		top = 0;
		left = 0;
		listBox = new ListBox();
		listBox.setWidth("625px");
		listBox.addChangeHandler(new ChangeHandler() {
			public void onChange(ChangeEvent event) {
				EmailContentVo emailContentVo = C._emailContentList.get(emailContentListBox.getSelectedIndex());
				orchardEmailSubject.setText(emailContentVo.subject);
				orchardEmailContent.setHTML(emailContentVo.content);
				//C._testMember = C._memberVo;
				//if (C._memberVo.contactList.size() != 0) C._testContact = C._memberVo.contactList.get(0);
				//if (C._memberVo.orchardList.size() != 0) C._testOrchard = C._memberVo.orchardList.get(0);

				//orchardEmailContentHTML.setHTML("<b>Subject: </b>" + C.templateToString(emailContentVo.subject, C._testMember, C._testContact, C._testOrchard) + "<br/><br/>" + C.templateToString(emailContentVo.content, C._testMember, C._testContact, C._testOrchard));
			}
		});
		this.emailContentListBox = listBox;
		tabPanel.add(listBox, left, top);

		html = new HTML("<b style='color:red'>Email Editor</b>");
		tabPanel.add(html, left + 640, top);

		top = 25;
		left = 0;

		textBox = new TextBox();
		textBox.setWidth("620px");
		this.orchardEmailSubject = textBox;
		/*
		RichTextArea richTextArea = new RichTextArea();
		richTextArea.setWidth("100%");
		richTextArea.setHeight("230px");
		RichTextToolbar richTextToolbar = new RichTextToolbar(richTextArea);
		this.orchardEmailContent = richTextArea;
		*/
		CKConfig ckc = CKConfig.full;

		// Creating personalized toolbar
		ToolbarLine line = new ToolbarLine();
		// Define the first line
		/*
		{ name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] },
		{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
		{ name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
		{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
		*/
		TOOLBAR_OPTIONS[] t1 = { TOOLBAR_OPTIONS.Source, TOOLBAR_OPTIONS._,
				//
				//TOOLBAR_OPTIONS.Save,TOOLBAR_OPTIONS.NewPage,TOOLBAR_OPTIONS.Preview, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Templates, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Cut, TOOLBAR_OPTIONS.Copy, TOOLBAR_OPTIONS.Paste, TOOLBAR_OPTIONS.PasteText, TOOLBAR_OPTIONS.PasteFromWord, TOOLBAR_OPTIONS._,
				//
				//TOOLBAR_OPTIONS.Print, 
				TOOLBAR_OPTIONS.SpellChecker, TOOLBAR_OPTIONS.Scayt, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Undo, TOOLBAR_OPTIONS.Redo, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Find, TOOLBAR_OPTIONS.Replace, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.SelectAll, TOOLBAR_OPTIONS.RemoveFormat, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Form, TOOLBAR_OPTIONS.Checkbox, TOOLBAR_OPTIONS.Radio, TOOLBAR_OPTIONS.TextField, TOOLBAR_OPTIONS.Textarea, TOOLBAR_OPTIONS.Select, TOOLBAR_OPTIONS.Button, TOOLBAR_OPTIONS.ImageButton, TOOLBAR_OPTIONS.HiddenField };
		line.addAll(t1);

		// Define the second line
		ToolbarLine line2 = new ToolbarLine();
		TOOLBAR_OPTIONS[] t2 = { TOOLBAR_OPTIONS.Bold, TOOLBAR_OPTIONS.Italic, TOOLBAR_OPTIONS.Underline, TOOLBAR_OPTIONS.Strike, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Subscript, TOOLBAR_OPTIONS.Superscript, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.NumberedList, TOOLBAR_OPTIONS.BulletedList, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Outdent, TOOLBAR_OPTIONS.Indent, TOOLBAR_OPTIONS.Blockquote, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.JustifyLeft, TOOLBAR_OPTIONS.JustifyCenter, TOOLBAR_OPTIONS.JustifyRight, TOOLBAR_OPTIONS.JustifyBlock, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Link, TOOLBAR_OPTIONS.Unlink, TOOLBAR_OPTIONS.Anchor, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Image, TOOLBAR_OPTIONS.Flash, TOOLBAR_OPTIONS.Table, TOOLBAR_OPTIONS.HorizontalRule, TOOLBAR_OPTIONS.Smiley, TOOLBAR_OPTIONS.SpecialChar, TOOLBAR_OPTIONS.PageBreak };
		line2.addAll(t2);

		//define the third line
		ToolbarLine line3 = new ToolbarLine();
		TOOLBAR_OPTIONS[] t3 = { TOOLBAR_OPTIONS.Styles, TOOLBAR_OPTIONS.Format, TOOLBAR_OPTIONS.Font, TOOLBAR_OPTIONS.FontSize, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.TextColor, TOOLBAR_OPTIONS.BGColor, TOOLBAR_OPTIONS._,
				//
				TOOLBAR_OPTIONS.Maximize, TOOLBAR_OPTIONS.ShowBlocks, TOOLBAR_OPTIONS.About };
		line3.addAll(t3);

		// Creates the toolbar
		Toolbar t = new Toolbar();
		t.add(line);
		t.addSeparator();
		t.add(line2);
		t.addSeparator();
		t.add(line3);

		ckc.setToolbar(t);
		//ckc.setSkin("office2003");
		ckc.setHeight("160px");

		this.orchardEmailContent = new CKEditor(true, ckc);
		this.orchardEmailContent.setWidth("750px");
		this.orchardEmailContent.setHeight("250px");
		/*
		Grid grid = new Grid(3, 1);
		grid.setStyleName("cw-RichText");
		grid.setWidget(0, 0, this.orchardEmailSubject);
		grid.setWidget(1, 0, this.orchardEmailContent);
		//grid.setWidget(2, 0, this.orchardEmailContent);
		grid.setBorderWidth(1);
		*/
		tabPanel.add(this.orchardEmailSubject, left, top);
		tabPanel.add(this.orchardEmailContent, left, top + 20);

		left = 670;

		html = new HTML("<img src='image/detail.gif' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				EmailContentVo emailContentVo = C._emailContentList.get(emailContentListBox.getSelectedIndex());
				C._testMember = C._memberVo;
				if (C._memberVo.contactList.size() != 0) C._testContact = C._memberVo.contactList.get(0);
				if (C._memberVo.orchardList.size() != 0) C._testOrchard = C._memberVo.orchardList.get(0);

				String html = "<b>Subject: </b>" + C.templateToString(emailContentVo.subject, C._testMember, C._testContact, C._testOrchard) + "<br/><br/>" + C.templateToString(emailContentVo.content, C._testMember, C._testContact, C._testOrchard);
				previewEmailEditor(html);
			}
		});
		tabPanel.add(html, left - 30, top);

		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("add new record?")) return;
				//C.adminViewS.saveMemberPropertyVo(getMemberPropertyVo(), memberPropertyCallback);
				/*
				if (C._emailContentList.size() != 0) {
					int i = emailContentListBox.getSelectedIndex();
					EmailContentVo emailContentVo = C._emailContentList.get(i);
					emailContentVo.subject = C.decode(orchardEmailSubject.getText());
					emailContentVo.content = C.decode(orchardEmailContent.getHTML());
				}
				*/
				EmailContentVo emailContentVo = new EmailContentVo();
				C._emailContentList.add(emailContentVo);
				C.adminViewS.viewEmailContentVoListSave(C._emailContentList, emailContentListCallback);
			}
		});
		tabPanel.add(html, left, top);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				//C.adminViewS.saveMemberPropertyVo(getMemberPropertyVo(), memberPropertyCallback);
				int i = emailContentListBox.getSelectedIndex();
				EmailContentVo emailContentVo = C._emailContentList.get(i);
				emailContentVo.subject = C.decode(orchardEmailSubject.getText());
				emailContentVo.content = C.decode(orchardEmailContent.getHTML());
				C.adminViewS.viewEmailContentVoListSave(C._emailContentList, emailContentListCallback);
			}
		});
		tabPanel.add(html, left + 30, top);

		html = new HTML("<img src='image/rem.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("delete this record?")) return;
				//C.adminViewS.saveMemberPropertyVo(getMemberPropertyVo(), memberPropertyCallback);
				int i = emailContentListBox.getSelectedIndex();
				C._emailContentList.remove(i);
				C.adminViewS.viewEmailContentVoListSave(C._emailContentList, emailContentListCallback);
			}
		});
		tabPanel.add(html, left + 60, top);

		top = 0;
		left = 750;

		html = new HTML("<b style='color:red'>SMS Editor</b>");
		tabPanel.add(html, left + 120, top);

		listBox = new ListBox();
		listBox.setWidth("115px");
		listBox.addChangeHandler(new ChangeHandler() {
			public void onChange(ChangeEvent event) {
				SmsContentVo smsContentVo = C._smsContentList.get(smsContentListBox.getSelectedIndex());
				smsSubject.setText(smsContentVo.subject);
				smsContent.setText(smsContentVo.content);

				htmlWords.setHTML("<b style='color:red'>Chars : " + smsContent.getText().length() + "</b>");
			}
		});
		this.smsContentListBox = listBox;
		tabPanel.add(listBox, left, top);

		top = 25;
		textBox = new TextBox();
		textBox.setWidth("110px");
		tabPanel.add(textBox, left, top);
		this.smsSubject = textBox;

		textArea = new TextArea();
		textArea.setWidth("220px");
		textArea.setHeight("260px");
		textArea.addChangeHandler(new ChangeHandler() {
			public void onChange(ChangeEvent event) {
				htmlWords.setHTML("<b style='color:red'>Words : " + smsContent.getText().length() + "</b>");
			}
		});
		textArea.addKeyUpHandler(new KeyUpHandler() {
			public void onKeyUp(KeyUpEvent event) {
				htmlWords.setHTML("<b style='color:red'>Words : " + smsContent.getText().length() + "</b>");
			}
		});
		tabPanel.add(textArea, left, top + 20);
		this.smsContent = textArea;

		html = new HTML("<b style='color:red'>Chars : 0</b>");
		tabPanel.add(html, left + 150, top + 290);
		this.htmlWords = html;

		left = left + 150;

		html = new HTML("<img src='image/detail.gif' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				SmsContentVo smsContentVo = C._smsContentList.get(smsContentListBox.getSelectedIndex());
				C._testMember = C._memberVo;
				if (C._memberVo.contactList.size() != 0) C._testContact = C._memberVo.contactList.get(0);
				if (C._memberVo.orchardList.size() != 0) C._testOrchard = C._memberVo.orchardList.get(0);

				String html = C.templateToString(smsContentVo.content, C._testMember, C._testContact, C._testOrchard);
				previewSmsEditor(html);
			}
		});
		tabPanel.add(html, left - 30, top);

		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("add new record?")) return;
				SmsContentVo smsContentVo = new SmsContentVo();
				C._smsContentList.add(smsContentVo);
				C.adminViewS.viewSmsContentVoListSave(C._smsContentList, smsContentListCallback);
			}
		});
		tabPanel.add(html, left, top);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				int i = smsContentListBox.getSelectedIndex();
				SmsContentVo smsContentVo = C._smsContentList.get(i);
				smsContentVo.subject = C.decode(smsSubject.getText());
				smsContentVo.content = C.decode(smsContent.getText());
				C.adminViewS.viewSmsContentVoListSave(C._smsContentList, smsContentListCallback);
			}
		});
		tabPanel.add(html, left + 30, top);

		html = new HTML("<img src='image/rem.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("20px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("delete this record?")) return;
				int i = smsContentListBox.getSelectedIndex();
				C._smsContentList.remove(i);
				C.adminViewS.viewSmsContentVoListSave(C._smsContentList, smsContentListCallback);
			}
		});
		tabPanel.add(html, left + 60, top);

		/*
		left = 0;
		top = 500;
		html = new HTML();
		html.setSize("953px", "498px");
		html.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		html.getElement().getStyle().setBorderWidth(1, Unit.PX);
		html.getElement().getStyle().setOverflow(Overflow.AUTO);
		this.orchardEmailContentHTML = html;
		tabPanel.add(html, left, top + 25);
		*/

		top = 330;
		left = 920;
		/*
		html = new HTML("<img src='image/dbStatus.png' style='cursor:pointer;width:24px;height:24px'/>");
		html.setWidth("35px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewEmailVoList(emailVoListCallback);
			}
		});
		tabPanel.add(html,left, top);
		*/

		listBox = new ListBox();
		listBox.addItem("All crop forecast contacts", "full");
		listBox.addItem("Found contacts from search", "search");

		listBox.addItem("All Email contacts", "email");
		listBox.addItem("All Fax contacts", "fax");
		listBox.addItem("All Sms contacts", "sms");
		listBox.addItem("All AMIA contacts", "amia");
		listBox.addItem("All Workshops contacts", "workshops");
		listBox.setWidth("170px");
		tabPanel.add(listBox, left - 110 - 70, top);
		this.emailListTypeBox = listBox;

		html = new HTML("<img src='image/mail.png' style='cursor:pointer;width:24px;height:24px'/>");
		html.setWidth("35px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("reload email sending list?")) return;
				idListOrchardEmail++;
				htmlMailSend.setVisible(false);
				tableRowRemove(tableOrchardEmail);

				String type = emailListTypeBox.getValue(emailListTypeBox.getSelectedIndex());
				if ("full".equals(type)) {
					C.adminViewS.viewEmailVoListReloadFull(null, emailVoListCallback);
				}
				/*else if ("search".equals(type)) {
					for (int i = 0; i < C._contactEmailList.size(); i++) {
						EmailVo emailVo = C._contactEmailList.get(i);
						emailVo.attempt = 0;
						emailVo.time = 0;
						emailVo.statusEmail = "";
						emailVo.statusFax = "";
						emailVo.statusSms = "";
					}
					emailVoListCallback.onSuccess(C._contactEmailList);
					} */
				else {
					C.adminViewS.viewEmailVoListReload(type, emailVoListCallback);
				}
			}
		});
		tabPanel.add(html, left, top);

		html = new HTML("<img src='image/mailSend.png' style='cursor:pointer;width:24px;height:24px'/>");
		html.setWidth("35px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("send email?")) return;
				htmlMailSend.setVisible(false);
				viewEmailVoSend(0, idListOrchardEmail);
				/*
				C.adminViewS.viewEmailVoListSend(emailContentListBox.getSelectedIndex(), new AsyncCallback<Void>() {

					public void onFailure(Throwable caught) {

					}

					public void onSuccess(Void result) {

					}
				});
				*/

			}
		});
		tabPanel.add(html, left + 35, top);
		this.htmlMailSend = html;
		htmlMailSend.setVisible(false);

		top = 355;
		left = 0;
		this.tableOrchardEmailHeader = new FlexTable();

		html = new HTML("<b><u>No</u></b>");
		html.setWidth("30px");
		this.tableOrchardEmailHeader.setWidget(0, 0, html);

		html = new HTML("<b><u>member</u></b>");
		html.setWidth("60px");
		this.tableOrchardEmailHeader.setWidget(0, 1, html);

		html = new HTML("<b><u>orchard</u></b>");
		html.setWidth("130px");
		this.tableOrchardEmailHeader.setWidget(0, 2, html);

		html = new HTML("<b><u>contact</u></b>");
		html.setWidth("130px");
		this.tableOrchardEmailHeader.setWidget(0, 3, html);

		html = new HTML("<b style='color:blue'><u>email</u></b>");
		html.setWidth("180px");
		this.tableOrchardEmailHeader.setWidget(0, 4, html);

		//html = new HTML("<b><u></u></b>");
		//html.setWidth("20px");
		//this.tableOrchardEmailHeader.setWidget(0, 5, html);
		checkBox = new CheckBox();
		checkBox.setWidth("20px");
		this.tableOrchardEmailHeader.setWidget(0, 5, checkBox);
		checkBox.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				for (int i = 0; i < tableOrchardEmail.getRowCount(); i++) {
					CheckBox cb = (CheckBox) event.getSource();
					CheckBox cb2 = (CheckBox) tableOrchardEmail.getWidget(i, 5);
					cb2.setValue(cb.getValue());
				}
			}
		});

		html = new HTML("<b style='color:blue'><u>status</u></b>");
		html.setWidth("50px");
		this.tableOrchardEmailHeader.setWidget(0, 6, html);

		html = new HTML("<b><u>fax</u></b>");
		html.setWidth("80px");
		this.tableOrchardEmailHeader.setWidget(0, 7, html);

		//html = new HTML("<b><u></u></b>");
		//html.setWidth("20px");
		//this.tableOrchardEmailHeader.setWidget(0, 8, html);
		checkBox = new CheckBox();
		checkBox.setWidth("20px");
		this.tableOrchardEmailHeader.setWidget(0, 8, checkBox);
		checkBox.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				for (int i = 0; i < tableOrchardEmail.getRowCount(); i++) {
					CheckBox cb = (CheckBox) event.getSource();
					CheckBox cb2 = (CheckBox) tableOrchardEmail.getWidget(i, 8);
					cb2.setValue(cb.getValue());
				}
			}
		});

		html = new HTML("<b><u>status</u></b>");
		html.setWidth("50px");
		this.tableOrchardEmailHeader.setWidget(0, 9, html);

		html = new HTML("<b style='color:blue'><u>sms</u></b>");
		html.setWidth("80px");
		this.tableOrchardEmailHeader.setWidget(0, 10, html);

		//html = new HTML("<b><u></u></b>");
		//html.setWidth("20px");
		//this.tableOrchardEmailHeader.setWidget(0, 11, html);
		checkBox = new CheckBox();
		checkBox.setWidth("20px");
		this.tableOrchardEmailHeader.setWidget(0, 11, checkBox);
		checkBox.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				for (int i = 0; i < tableOrchardEmail.getRowCount(); i++) {
					CheckBox cb = (CheckBox) event.getSource();
					CheckBox cb2 = (CheckBox) tableOrchardEmail.getWidget(i, 11);
					cb2.setValue(cb.getValue());
				}
			}
		});

		html = new HTML("<b style='color:blue'><u>status</u></b>");
		html.setWidth("50px");
		this.tableOrchardEmailHeader.setWidget(0, 12, html);

		html = new HTML("<b><u>try</u></b>");
		html.setWidth("30px");
		this.tableOrchardEmailHeader.setWidget(0, 13, html);

		html = new HTML("<b><u>time</u></b>");
		html.setWidth("30px");
		this.tableOrchardEmailHeader.setWidget(0, 14, html);

		tabPanel.add(this.tableOrchardEmailHeader, left, top);

		tablePanel = new AbsolutePanel();
		this.tableOrchardEmail = new FlexTable();
		this.tableOrchardEmail.setBorderWidth(1);
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 14 - 360 + "px");
		tablePanel.add(this.tableOrchardEmail, 0, 2);
		tabPanel.add(tablePanel, left, top + 16);

		//tabPanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tab.add(tabPanel, "Orchard Email");

		//TODO: Flower
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		this.htmlTotalTree = new HTML();
		tabPanel.add(this.htmlTotalTree, left, top);

		this.tableTree = new FlexTable();
		tabPanel.add(this.tableTree, left, top + 16);

		top = 80;
		left = 0;

		this.tableFlowerHeader = new FlexTable();

		html = new HTML("<b><u>contact</u></b>");
		html.setWidth("100px");
		this.tableFlowerHeader.setWidget(0, 0, html);

		html = new HTML("<b><u>block</u></b>");
		html.setWidth("100px");
		this.tableFlowerHeader.setWidget(1, 0, html);

		html = new HTML("<b><u>region</u></b>");
		html.setWidth("100px");
		this.tableFlowerHeader.setWidget(0, 1, html);

		html = new HTML("<b><u>sub-region</u></b>");
		html.setWidth("100px");
		this.tableFlowerHeader.setWidget(1, 1, html);

		html = new HTML("<b><u>variety</u></b>");
		html.setWidth("100px");
		this.tableFlowerHeader.setWidget(0, 2, html);

		html = new HTML("<b><u>trees</u></b>");
		html.setWidth("100px");
		this.tableFlowerHeader.setWidget(1, 2, html);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("30px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				C.adminViewS.viewFlowerSave(C._memberVo.memberId + "", getFlowerList(), flowerListCallback);
			}
		});
		this.tableFlowerHeader.setWidget(0, 3, html);
		tabPanel.add(this.tableFlowerHeader, left, top);

		tablePanel = new AbsolutePanel();
		this.tableFlower = new FlexTable();
		tablePanel.getElement().getStyle().setOverflow(Overflow.SCROLL);
		tablePanel.setSize(width + "px", height - 14 - 80 + "px");
		tablePanel.add(this.tableFlower, 0, 2);
		tabPanel.add(tablePanel, left, top + 32);

		tab.add(tabPanel, "Flower");
		this.panel.add(tab, 0, 30);

		//TODO: Summary
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 80;
		left = 0;

		this.tableSummaryHeader = new FlexTable();

		html = new HTML("<b><u>contact</u></b>");
		html.setWidth("100px");
		this.tableSummaryHeader.setWidget(0, 0, html);

		html = new HTML("<b><u>block</u></b>");
		html.setWidth("100px");
		this.tableSummaryHeader.setWidget(1, 0, html);

		html = new HTML("<b><u>region</u></b>");
		html.setWidth("100px");
		this.tableSummaryHeader.setWidget(0, 1, html);

		html = new HTML("<b><u>sub-region</u></b>");
		html.setWidth("100px");
		this.tableSummaryHeader.setWidget(1, 1, html);

		html = new HTML("<b><u>variety</u></b>");
		html.setWidth("100px");
		this.tableSummaryHeader.setWidget(0, 2, html);

		html = new HTML("<b><u>trees</u></b>");
		html.setWidth("100px");
		this.tableSummaryHeader.setWidget(1, 2, html);

		html = new HTML("<div/>");
		html.setWidth("30px");
		this.tableSummaryHeader.setWidget(0, 3, html);

		tabPanel.add(this.tableSummaryHeader, left, top);

		tablePanel = new AbsolutePanel();
		this.tableSummary = new FlexTable();
		tablePanel.getElement().getStyle().setOverflow(Overflow.SCROLL);
		tablePanel.setSize(width + "px", height - 14 - 80 + "px");
		tablePanel.add(this.tableSummary, 0, 2);
		tabPanel.add(tablePanel, left, top + 32);

		tab.add(tabPanel, "Summary");
		this.panel.add(tab, 0, 30);

		//TODO: Chart
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		this.tableRegionSelect = new FlexTable();
		this.tableRegionSelect.setWidth(width - 30 + "px");

		tabPanel.add(this.tableRegionSelect, left, top);

		html = new HTML("<img src='image/ok.png' style='cursor:pointer;width:24px;height:24px'/>");
		html.setWidth("30px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("draw the chart?")) return;
				C.adminViewS.viewFlowerChart(getRegionSelectIdList(), flowerChartListCallback);

			}
		});
		tabPanel.add(html, width - 30, top);
		/*
		FlowerChart chart = new FlowerChart();
		chart.setXChartSize(width - 200);
		chart.setYChartSize(height - 120);
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 14 + "px");
		tablePanel.add(chart, 0, 2);
		tabPanel.add(tablePanel, left, top + 16);
		this.flowerChart = chart;
		*/

		FlowerChart chart = new FlowerChart();
		chart.setSize(width - 30 + "px", height - 30 - 3 * 16 + "px");
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 14 - 3 * 16 + "px");
		tablePanel.add(chart, 0, 2);
		this.flowerChart = chart;

		chart = new FlowerChart();
		chart.setSize(width - 30 + "px", height - 30 - 3 * 16 + "px");
		tablePanel.add(chart, 0, 2 + height - 30 - 3 * 16 + 50);
		tabPanel.add(tablePanel, left, top + 4 * 16);
		this.flowerChart2 = chart;

		tab.add(tabPanel, "Chart");

		//TODO: LookupT
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		this.tableLookupTHeader = new FlexTable();

		html = new HTML("<b><u>region</u></b>");
		html.setWidth("150px");
		this.tableLookupTHeader.setWidget(0, 0, html);

		html = new HTML("<b><u>variety</u></b>");
		html.setWidth("150px");
		this.tableLookupTHeader.setWidget(0, 1, html);

		html = new HTML("<b><u>heat</u></b>");
		html.setWidth("50px");
		this.tableLookupTHeader.setWidget(0, 2, html);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				C.adminViewS.viewLookupTSave(getLookupTList(), lookupTListCallback);
			}
		});
		this.tableLookupTHeader.setWidget(0, 3, html);
		tabPanel.add(this.tableLookupTHeader, left, top);

		tablePanel = new AbsolutePanel();
		this.tableLookupT = new FlexTable();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 14 + "px");
		tablePanel.add(this.tableLookupT, 0, 2);
		tabPanel.add(tablePanel, left, top + 16);

		tab.add(tabPanel, "LookupT");

		//TODO: Temperature
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		this.tableTemperatureHeader = new FlexTable();

		html = new HTML("<b><u>regionName</u></b>");
		html.setWidth("150px");
		this.tableTemperatureHeader.setWidget(0, 0, html);
		listBox = new ListBox();
		listBox.setWidth(getWidth(html) - 0 + "px");
		this.tableTemperatureHeader.setWidget(1, 0, listBox);
		listBox.addChangeHandler(new ChangeHandler() {
			public void onChange(ChangeEvent event) {
				ListBox listBox = (ListBox) event.getSource();
				TextBox textBox;
				String regionId = listBox.getValue(listBox.getSelectedIndex());
				TemperatureUrlVo temperatureUrlVo = C._temperatureUrlVoMap.get(regionId);
				if (temperatureUrlVo == null) {
					temperatureUrlVo = new TemperatureUrlVo();
					try {
						temperatureUrlVo.regionId = Integer.parseInt(regionId);
					} catch (Exception e) {
					}
				}

				textBox = (TextBox) tableTemperatureHeader.getWidget(1, 1);
				textBox.setText(temperatureUrlVo.minUrl);
				textBox = (TextBox) tableTemperatureHeader.getWidget(1, 2);
				textBox.setText(temperatureUrlVo.maxUrl);
				htmlTemperature.setHTML("");
			}
		});

		html = new HTML("<b><u>minTempUrl</u></b>");
		html.setWidth("380px");
		this.tableTemperatureHeader.setWidget(0, 1, html);
		textBox = new TextBox();
		textBox.setWidth(getWidth(html) - 6 + "px");
		this.tableTemperatureHeader.setWidget(1, 1, textBox);

		html = new HTML("<b><u>maxTempUrl</u></b>");
		html.setWidth("380px");
		this.tableTemperatureHeader.setWidget(0, 2, html);
		textBox = new TextBox();
		textBox.setWidth(getWidth(html) - 6 + "px");
		this.tableTemperatureHeader.setWidget(1, 2, textBox);

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("40px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("save this record?")) return;
				C.adminViewS.viewTemperatureSave(getTemperatureUrlVo(), temperatureCallback);
			}
		});
		this.tableTemperatureHeader.setWidget(0, 3, html);
		tabPanel.add(this.tableTemperatureHeader, left, top);

		tablePanel = new AbsolutePanel();
		this.htmlTemperature = new HTML();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height - 50 + "px");
		tablePanel.add(this.htmlTemperature, 0, 2);
		tabPanel.add(tablePanel, left, top + 50);

		tab.add(tabPanel, "Temperature");
		/////////////////////////////////

		//TODO: Help
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		tablePanel = new AbsolutePanel();
		this.htmlHelp = new HTML();
		this.setHelp();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height + "px");
		tablePanel.add(this.htmlHelp, 0, 2);
		tabPanel.add(tablePanel, left, top);

		tab.add(tabPanel, "Help");
		/////////////////////////////////

		this.panel.add(tab, 0, 30);

		//TODO: Test
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width + "px", height + "px");

		top = 0;
		left = 0;

		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width + "px", height + "px");

		textBox = new TextBox();
		textBox.setText("+84906941602");
		final TextBox number = textBox;
		tablePanel.add(textBox, 0, 2);

		textBox = new TextBox();
		textBox.setText("Hello SMS");
		final TextBox msg = textBox;
		tablePanel.add(textBox, 0, 32);

		button = new Button("Send SMS");
		button.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.sendSMS(number.getText(), msg.getText(), new AsyncCallback<String>() {
					public void onFailure(Throwable caught) {
					}

					public void onSuccess(String result) {
						Window.alert(result);
					}
				});

			}
		});
		tablePanel.add(button, 0, 62);
		tabPanel.add(tablePanel, left, top);

		tab.add(tabPanel, "SMS/Fax Test");
		/////////////////////////////////

		tab.selectTab(3);
		this.panel.add(tab, 0, 30);

		// TODO:AdminSearchView
		this.dialogBox = new DialogBox();
		this.dialogBox.setHTML("<b style='color:red'>Database Management</b>");
		this.dialogBox.setModal(false);
		this.dialogBox.setWidget(this.panel);

		//A.adminViewS.viewAdminDb(this.adminDbVoCallback);
		//this.adminDbVoCallback.onSuccess(A.adminDbVo);

		return this;
	}

	public AdminDbView view() {
		if (C._varietyVoList != null) this.varietyListCallback.onSuccess(C._varietyVoList);
		if (C._regionVoList != null) {
			this.regionListCallback.onSuccess(C._regionVoList);
			this.setTemperatureUrlMap();
		}
		if (C._memberPropertyVo != null) this.memberPropertyCallback.onSuccess(C._memberPropertyVo);
		///////////if (C._emailVoList != null) this.emailVoListCallback.onSuccess(C._emailVoList);
		if (C._emailContentList != null) this.emailContentListCallback.onSuccess(C._emailContentList);
		if (C._smsContentList != null) this.smsContentListCallback.onSuccess(C._smsContentList);
		if (C._lookupTVoList != null) this.lookupTListCallback.onSuccess(C._lookupTVoList);
		//if (C._memberVo != null) this.flowerListCallback.onSuccess(C._memberVo.flowerList);
		return this;
	}

	public DialogBox dialogBox;

	public AdminDbView viewDb() {
		this.dialogBox.hide();
		return this;
	}

	public AdminDbView viewShow() {
		this.dialogBox.show();
		ChangeEvent.fireNativeEvent(Document.get().createChangeEvent(), emailContentListBox);
		return this;
	}

	public AsyncCallback<MemberPropertyVo> memberPropertyCallback = new AsyncCallback<MemberPropertyVo>() {
		public void onSuccess(MemberPropertyVo memberPropertyVo) {
			C._memberPropertyVo = memberPropertyVo;

			tableRowRemove(tableMemberProperty);
			HTML html;

			html = new HTML("<b style='color:red;height:60'>System email settings</b>");
			tableMemberProperty.setWidget(0, 1, html);

			html = new HTML("STMPserver");
			tableMemberProperty.setWidget(1, 0, html);
			TextBox textBox = newTextBox(C._memberPropertyVo.STMPserver, 200);
			tableMemberProperty.setWidget(1, 1, textBox);

			html = new HTML("email");
			tableMemberProperty.setWidget(2, 0, html);
			textBox = newTextBox(C._memberPropertyVo.email, 200);
			tableMemberProperty.setWidget(2, 1, textBox);

			html = new HTML("account");
			tableMemberProperty.setWidget(3, 0, html);
			textBox = newTextBox(C._memberPropertyVo.account, 200);
			tableMemberProperty.setWidget(3, 1, textBox);

			html = new HTML("pass");
			tableMemberProperty.setWidget(4, 0, html);
			PasswordTextBox passwordTextBox = new PasswordTextBox();
			passwordTextBox.setText(C._memberPropertyVo.pass);
			passwordTextBox.setWidth(200 + "px");
			tableMemberProperty.setWidget(4, 1, passwordTextBox);

			/////////
			html = new HTML("<b style='color:red;height:60'>Secrectary email settings</b>");
			tableMemberProperty.setWidget(5, 1, html);

			html = new HTML("STMPserver");
			tableMemberProperty.setWidget(6, 0, html);
			textBox = newTextBox(C._memberPropertyVo.STMPserverSec, 200);
			tableMemberProperty.setWidget(6, 1, textBox);

			html = new HTML("email");
			tableMemberProperty.setWidget(7, 0, html);
			textBox = newTextBox(C._memberPropertyVo.emailSec, 200);
			tableMemberProperty.setWidget(7, 1, textBox);

			html = new HTML("account");
			tableMemberProperty.setWidget(8, 0, html);
			textBox = newTextBox(C._memberPropertyVo.accountSec, 200);
			tableMemberProperty.setWidget(8, 1, textBox);

			html = new HTML("pass");
			tableMemberProperty.setWidget(9, 0, html);
			passwordTextBox = new PasswordTextBox();
			passwordTextBox.setText(C._memberPropertyVo.passSec);
			passwordTextBox.setWidth(200 + "px");
			tableMemberProperty.setWidget(9, 1, passwordTextBox);

			///////////////
			html = new HTML("<b style='color:red;height:60'>Crop forecast settings</b>");
			tableMemberProperty.setWidget(10, 1, html);

			html = new HTML("startMonth");
			tableMemberProperty.setWidget(11, 0, html);
			textBox = newTextBox(C._memberPropertyVo.startMonth + "", 200);
			tableMemberProperty.setWidget(11, 1, textBox);

			html = new HTML("startDay");
			tableMemberProperty.setWidget(12, 0, html);
			textBox = newTextBox(C._memberPropertyVo.startDay + "", 200);
			tableMemberProperty.setWidget(12, 1, textBox);

			html = new HTML("interval");
			tableMemberProperty.setWidget(13, 0, html);
			textBox = newTextBox(C._memberPropertyVo.interval + "", 200);
			tableMemberProperty.setWidget(13, 1, textBox);

			html = new HTML("columns");
			tableMemberProperty.setWidget(14, 0, html);
			textBox = newTextBox(C._memberPropertyVo.columns + "", 200);
			tableMemberProperty.setWidget(14, 1, textBox);

			///////////////////orchardEmailSubject.setText(C._memberPropertyVo.orchardEmailSubject);
			///////////////////orchardEmailContent.setHTML(C._memberPropertyVo.orchardEmailContent);
			///////////////////orchardEmailContentHTML.setHTML("<b>Subject: </b>" + C.templateToString(C._memberPropertyVo.orchardEmailSubject, C._testMember, C._testContact, C._testOrchard) + "<br/><br/>" + C.templateToString(C._memberPropertyVo.orchardEmailContent, C._testMember, C._testContact, C._testOrchard));
		}

		public void onFailure(Throwable caught) {
		}
	};

	public MemberPropertyVo getMemberPropertyVo() {
		C._memberPropertyVo.STMPserver = ((TextBox) this.tableMemberProperty.getWidget(1, 1)).getText();
		C._memberPropertyVo.email = ((TextBox) this.tableMemberProperty.getWidget(2, 1)).getText();
		C._memberPropertyVo.account = ((TextBox) this.tableMemberProperty.getWidget(3, 1)).getText();
		C._memberPropertyVo.pass = ((TextBox) this.tableMemberProperty.getWidget(4, 1)).getText();

		C._memberPropertyVo.STMPserverSec = ((TextBox) this.tableMemberProperty.getWidget(6, 1)).getText();
		C._memberPropertyVo.emailSec = ((TextBox) this.tableMemberProperty.getWidget(7, 1)).getText();
		C._memberPropertyVo.accountSec = ((TextBox) this.tableMemberProperty.getWidget(8, 1)).getText();
		C._memberPropertyVo.passSec = ((TextBox) this.tableMemberProperty.getWidget(9, 1)).getText();

		try {
			C._memberPropertyVo.startMonth = Integer.parseInt(((TextBox) this.tableMemberProperty.getWidget(11, 1)).getText());
			C._memberPropertyVo.startDay = Integer.parseInt(((TextBox) this.tableMemberProperty.getWidget(12, 1)).getText());
			C._memberPropertyVo.interval = Integer.parseInt(((TextBox) this.tableMemberProperty.getWidget(13, 1)).getText());
			C._memberPropertyVo.columns = Integer.parseInt(((TextBox) this.tableMemberProperty.getWidget(14, 1)).getText());
		} catch (Exception ex) {
		}

		return C._memberPropertyVo;
	}

	public AsyncCallback<List<EmailVo>> emailVoListCallback = new AsyncCallback<List<EmailVo>>() {
		public void onSuccess(List<EmailVo> emailVoList) {
			C._emailVoList = emailVoList;

			tableRowRemove(tableOrchardEmail);

			for (int i = 0; i < emailVoList.size(); i++) {
				EmailVo emailVo = emailVoList.get(i);

				HTML html = new HTML("" + (i + 1));
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 0, html);

				html = new HTML("<a onclick='return false;'>" + emailVo.memberId + "</a>");
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 1).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 1, html);
				html.getElement().setAttribute("memberId", emailVo.memberId + "");
				html.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						HTML htm = (HTML) event.getSource();
						AdminView.get("").gotoMember(htm.getElement().getAttribute("memberId"));
					}
				});

				html = new HTML(emailVo.orchardHeader);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 2).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 2, html);

				html = new HTML(emailVo.contactHeader);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 3).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 3, html);

				html = new HTML(emailVo.email);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 4).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 4, html);

				CheckBox box = new CheckBox();
				//box.setValue(true);
				tableOrchardEmail.setWidget(i, 5, box);

				html = new HTML(emailVo.statusEmail);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 6).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 6, html);

				html = new HTML(emailVo.fax);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 7).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 7, html);

				box = new CheckBox();
				tableOrchardEmail.setWidget(i, 8, box);

				html = new HTML(emailVo.statusFax);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 9).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 9, html);

				html = new HTML(emailVo.sms);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 10).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 10, html);

				box = new CheckBox();
				tableOrchardEmail.setWidget(i, 11, box);

				html = new HTML(emailVo.statusSms);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 12).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 12, html);

				html = new HTML("" + emailVo.attempt);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 13).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 13, html);

				html = new HTML("" + emailVo.time);
				html.setWidth(tableOrchardEmailHeader.getWidget(0, 14).getElement().getStyle().getWidth());
				tableOrchardEmail.setWidget(i, 14, html);

			}
			htmlMailSend.setVisible(true);
		}

		public void onFailure(Throwable caught) {
		}
	};

	public void viewEmailVoSend(int id, int idList) {
		if (id >= C._emailVoList.size()) return;
		EmailVo emailVo = C._emailVoList.get(id);
		emailVo.id = id;
		emailVo.idList = idList;

		emailVo.statusEmail = "skip";
		emailVo.statusFax = "skip";
		emailVo.statusSms = "skip";

		CheckBox box = (CheckBox) tableOrchardEmail.getWidget(emailVo.id, 5);
		if (box.getValue()) emailVo.statusEmail = "sending";

		box = (CheckBox) tableOrchardEmail.getWidget(emailVo.id, 8);
		if (box.getValue()) emailVo.statusFax = "sending";

		box = (CheckBox) tableOrchardEmail.getWidget(emailVo.id, 11);
		if (box.getValue()) emailVo.statusSms = "sending";

		if ("".equals(emailVo.email.trim())) emailVo.statusEmail = "skip";
		if ("".equals(emailVo.fax.trim())) emailVo.statusFax = "skip";
		if ("".equals(emailVo.sms.trim())) emailVo.statusSms = "skip";

		if ("skip".equals(emailVo.statusEmail) && "skip".equals(emailVo.statusFax) && "skip".equals(emailVo.statusSms)) {

		}

		C.adminViewS.viewEmailVoSend(emailVo, emailContentListBox.getSelectedIndex(), smsContentListBox.getSelectedIndex(), new AsyncCallback<EmailVo>() {

			public void onSuccess(EmailVo _emailVo) {
				if (_emailVo.idList != idListOrchardEmail) return;
				HTML html = (HTML) tableOrchardEmail.getWidget(_emailVo.id, 6);
				html.setText(_emailVo.statusEmail);

				html = (HTML) tableOrchardEmail.getWidget(_emailVo.id, 9);
				html.setText(_emailVo.statusFax);

				html = (HTML) tableOrchardEmail.getWidget(_emailVo.id, 12);
				html.setText(_emailVo.statusSms);

				html = (HTML) tableOrchardEmail.getWidget(_emailVo.id, 13);
				html.setText(_emailVo.attempt + "");

				html = (HTML) tableOrchardEmail.getWidget(_emailVo.id, 14);
				html.setText(_emailVo.time + "");

				viewEmailVoSend(_emailVo.id + 1, _emailVo.idList);
			}

			public void onFailure(Throwable caught) {
			}
		});
	}

	public AsyncCallback<List<EmailContentVo>> emailContentListCallback = new AsyncCallback<List<EmailContentVo>>() {
		public void onSuccess(List<EmailContentVo> emailContentList) {
			C._emailContentList = emailContentList;
			int selectedIndex = 0;
			if (emailContentList.size() == emailContentListBox.getItemCount()) {
				selectedIndex = emailContentListBox.getSelectedIndex();
			} else if (emailContentList.size() == emailContentListBox.getItemCount() + 1) {
				selectedIndex = emailContentList.size() - 1;
			} else if (emailContentList.size() == emailContentListBox.getItemCount() - 1) {
				selectedIndex = emailContentListBox.getSelectedIndex();
				if (selectedIndex == emailContentList.size()) selectedIndex = selectedIndex - 1;
			}

			if (C._emailContentList.size() == 0) {
				EmailContentVo emailContentVo = new EmailContentVo();
				C._emailContentList.add(emailContentVo);
				selectedIndex = 0;
			}

			emailContentListBox.clear();
			for (int i = 0; i < C._emailContentList.size(); i++) {
				EmailContentVo emailContentVo = C._emailContentList.get(i);
				emailContentListBox.addItem(emailContentVo.subject, i + "");
			}
			emailContentListBox.setSelectedIndex(selectedIndex);
			ChangeEvent.fireNativeEvent(Document.get().createChangeEvent(), emailContentListBox);
		}

		public void onFailure(Throwable caught) {
		}
	};

	public AsyncCallback<List<SmsContentVo>> smsContentListCallback = new AsyncCallback<List<SmsContentVo>>() {
		public void onSuccess(List<SmsContentVo> smsContentList) {
			C._smsContentList = smsContentList;
			int selectedIndex = 0;
			if (smsContentList.size() == smsContentListBox.getItemCount()) {
				selectedIndex = smsContentListBox.getSelectedIndex();
			} else if (smsContentList.size() == smsContentListBox.getItemCount() + 1) {
				selectedIndex = smsContentList.size() - 1;
			} else if (smsContentList.size() == smsContentListBox.getItemCount() - 1) {
				selectedIndex = smsContentListBox.getSelectedIndex();
				if (selectedIndex == smsContentList.size()) selectedIndex = selectedIndex - 1;
			}

			if (C._smsContentList.size() == 0) {
				SmsContentVo smsContentVo = new SmsContentVo();
				C._smsContentList.add(smsContentVo);
				selectedIndex = 0;
			}

			smsContentListBox.clear();
			for (int i = 0; i < C._smsContentList.size(); i++) {
				SmsContentVo smsContentVo = C._smsContentList.get(i);
				smsContentListBox.addItem(smsContentVo.subject, i + "");
			}
			smsContentListBox.setSelectedIndex(selectedIndex);
			ChangeEvent.fireNativeEvent(Document.get().createChangeEvent(), smsContentListBox);
		}

		public void onFailure(Throwable caught) {
		}
	};

	public AsyncCallback<List<FlowerVo>> flowerListCallback = new AsyncCallback<List<FlowerVo>>() {
		public void onSuccess(List<FlowerVo> flowerList) {
			C._memberVo.flowerList = flowerList;
			ListBox listBox;
			TextBox textBox;
			HTML html;

			htmlTotalTree.setHTML("<b style='color:red'>Total Trees for " + C._memberVo.businessName + " is " + AdminView.get("").totalTree + "</b>");

			tableRowRemove(tableTree);
			Map<String, Integer> treeCountMap = AdminView.get("").treeCountMap;
			int i = 0;
			for (String varietyName : treeCountMap.keySet()) {
				int row = i / 5;
				int column = i % 5;
				Integer count = treeCountMap.get(varietyName);
				html = new HTML("<b>" + varietyName + " : </b>" + count);
				html.setWidth("200px");
				tableTree.setWidget(row, column, html);
				i++;
			}

			Integer width = 60;
			int row = 10 + flowerList.size();

			List<String> startFlowerDateList = C.getStartFlowerDateList("dd-MMM");
			List<String> endFlowerDateList = C.getEndFlowerDateList("dd-MMM");

			for (int j = 0; j < C._memberPropertyVo.columns; j++) {
				html = new HTML("<b>" + startFlowerDateList.get(j) + "</b>");
				html.setWidth(width + "px");
				tableFlowerHeader.setWidget(0, 4 + j, html);
				html = new HTML("<b>" + endFlowerDateList.get(j) + "</b>");
				html.setWidth(width + "px");
				tableFlowerHeader.setWidget(1, 4 + j, html);
			}

			tableRowRemove(tableFlower);
			int row2 = 10;
			for (i = 0; i < flowerList.size(); i++) {
				FlowerVo flower = flowerList.get(i);
				if (!C._memberVo.memberId.equals(flower.memberId)) continue;
				row2++;
			}
			for (i = 0; i < row2; i++) {
				//TODO: contact

				listBox = new ListBox();
				//listBox.getElement().getStyle().setBorderColor("GREEN");
				listBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 0)) - 0 + "px");
				listBox.addItem("", "");
				for (int j = 0; j < C._memberVo.contactList.size(); j++) {
					listBox.addItem(C._memberVo.contactList.get(j).getCaption(), C._memberVo.contactList.get(j).getCaption());
				}
				tableFlower.setWidget(2 * i + 0, 0, listBox);

				//TODO: block
				textBox = new TextBox();
				//textBox.getElement().getStyle().setBorderColor("RED");
				textBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 0)) - 6 + "px");
				tableFlower.setWidget(2 * i + 1, 0, textBox);

				//TODO: region
				listBox = new ListBox();
				//listBox.getElement().getStyle().setBorderColor("GREEN");
				listBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 1)) - 0 + "px");
				listBox.addItem("", "");
				for (int j = 0; j < C._regionVoList.size(); j++) {
					listBox.addItem(C._regionVoList.get(j).regionName, C._regionVoList.get(j).regionId + "");
				}
				listBox.getElement().setAttribute("i", i + "");
				listBox.addChangeHandler(new ChangeHandler() {
					public void onChange(ChangeEvent event) {
						ListBox listBox = (ListBox) event.getSource();
						int i = Integer.parseInt(listBox.getElement().getAttribute("i"));
						int j = listBox.getSelectedIndex();
						RegionVo regionVo = null;
						if (j - 1 >= 0) {
							regionVo = C._regionVoList.get(j - 1);
						}

						listBox = (ListBox) tableFlower.getWidget(2 * i + 1, 1);
						listBox.clear();
						listBox.addItem("", "");
						if (regionVo != null) {
							List<String> subRegionList = regionVo.getStringList(regionVo.subRegions);
							for (int k = 0; k < subRegionList.size(); k++) {
								listBox.addItem(subRegionList.get(k), subRegionList.get(k));
							}
						}
					}
				});
				tableFlower.setWidget(2 * i + 0, 1, listBox);

				//TODO: subRegion
				listBox = new ListBox();
				//listBox.getElement().getStyle().setBorderColor("RED");
				listBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 1)) - 0 - 0 + "px");
				listBox.addItem("", "");
				tableFlower.setWidget(2 * i + 1, 1, listBox);

				//TODO: variety
				listBox = new ListBox();
				//listBox.getElement().getStyle().setBorderColor("GREEN");
				listBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 2)) - 0 + "px");
				listBox.addItem("", "");
				for (int j = 0; j < C._varietyVoList.size(); j++) {
					listBox.addItem(C._varietyVoList.get(j).varietyName, C._varietyVoList.get(j).varietyId + "");
				}
				tableFlower.setWidget(2 * i + 0, 2, listBox);

				//TODO: tree
				textBox = new TextBox();
				//textBox.getElement().getStyle().setBorderColor("RED");
				textBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 2)) - 6 + "px");
				tableFlower.setWidget(2 * i + 1, 2, textBox);

				//TODO: count
				html = new HTML("<b>" + (i + 1) + "</b>");
				html.setWidth(getWidth(tableFlowerHeader.getWidget(0, 3)) + "px");
				html.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
				tableFlower.setWidget(2 * i + 0, 3, html);

				for (int j = 0; j < C._memberPropertyVo.columns; j++) {
					textBox = new TextBox();
					textBox.setWidth(getWidth(tableFlowerHeader.getWidget(0, 4 + j)) - 8 + "px");
					tableFlower.setWidget(2 * i + 0, 4 + j, textBox);

					html = new HTML("");
					html.setWidth(getWidth(tableFlowerHeader.getWidget(0, 4 + j)) + "px");
					tableFlower.setWidget(2 * i + 1, 4 + j, html);
				}

				tableFlower.getRowFormatter().getElement(2 * i + 0).getStyle().setProperty("borderTop", "2px solid BLUE");
			}

			for (int j = 0; j < C._memberPropertyVo.columns; j++) {
				html = new HTML("<b>" + startFlowerDateList.get(j) + "</b>");
				html.setWidth(width + "px");
				tableSummaryHeader.setWidget(0, 4 + j, html);
				html = new HTML("<b>" + endFlowerDateList.get(j) + "</b>");
				html.setWidth(width + "px");
				tableSummaryHeader.setWidget(1, 4 + j, html);
			}

			tableRowRemove(tableSummary);
			for (i = 0; i < row; i++) {
				//TODO: contact
				html = new HTML();
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 0)) + "px");
				html.setHeight("20px");
				tableSummary.setWidget(2 * i + 0, 0, html);

				//TODO: block
				html = new HTML();
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 0)) + "px");
				html.setHeight("20px");
				tableSummary.setWidget(2 * i + 1, 0, html);

				//TODO: region
				html = new HTML();
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 1)) + "px");
				tableSummary.setWidget(2 * i + 0, 1, html);

				//TODO: subRegion
				html = new HTML();
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 1)) + "px");
				tableSummary.setWidget(2 * i + 1, 1, html);

				//TODO: variety
				html = new HTML();
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 2)) + "px");
				tableSummary.setWidget(2 * i + 0, 2, html);

				//TODO: tree
				html = new HTML();
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 2)) + "px");
				tableSummary.setWidget(2 * i + 1, 2, html);

				//TODO: count
				html = new HTML("<b>" + (i + 1) + "</b>");
				html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 3)) + "px");
				html.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
				tableSummary.setWidget(2 * i + 0, 3, html);

				for (int j = 0; j < C._memberPropertyVo.columns; j++) {
					html = new HTML();
					html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 4 + j)) + "px");
					tableSummary.setWidget(2 * i + 0, 4 + j, html);

					html = new HTML("");
					html.setWidth(getWidth(tableSummaryHeader.getWidget(0, 4 + j)) + "px");
					tableSummary.setWidget(2 * i + 1, 4 + j, html);
				}

				tableSummary.getRowFormatter().getElement(2 * i + 0).getStyle().setProperty("borderTop", "2px solid BLUE");
			}

			setFlowerList(C._memberVo.flowerList);
		}

		public void onFailure(Throwable caught) {
		}
	};

	public AsyncCallback<Map<String, Map<String, FlowerChartVo>>> flowerChartListCallback = new AsyncCallback<Map<String, Map<String, FlowerChartVo>>>() {
		public void onSuccess(Map<String, Map<String, FlowerChartVo>> flowerChartList) {
			C._flowerChartList = flowerChartList;
			//flowerChart2.setChartData(getChartData(0));
			//flowerChart.setChartData(getChartData(1));
			//flowerChart2.update();
			flowerChart.update("region");
			flowerChart2.update("variety");
		}

		public void onFailure(Throwable caught) {
		}
	};

	public AsyncCallback<List<VarietyVo>> varietyListCallback = new AsyncCallback<List<VarietyVo>>() {
		public void onSuccess(List<VarietyVo> varietyVoList) {
			C._varietyVoList = varietyVoList;

			HTML html;
			TextBox textBox;
			tableRowRemove(tableVariety);
			for (int i = 0; i < C._varietyVoList.size(); i++) {
				VarietyVo varietyVo = C._varietyVoList.get(i);

				html = new HTML(varietyVo.varietyId + "");
				html.setWidth(tableVarietyHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableVariety.setWidget(i, 0, html);

				textBox = newTextBox(varietyVo.varietyName, 200);
				textBox.setWidth(tableVarietyHeader.getWidget(0, 1).getElement().getStyle().getWidth());
				tableVariety.setWidget(i, 1, textBox);

				html = new HTML("<img src='image/remove.png' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						VarietyVo varietyVo = C._varietyVoList.get(index);
						C.adminViewS.viewVarietyRemove(varietyVo.varietyId, varietyListCallback);
					}
				});
				html.setWidth(tableVarietyHeader.getWidget(0, 2).getElement().getStyle().getWidth());
				tableVariety.setWidget(i, 2, html);
			}
		}

		public void onFailure(Throwable caught) {
		}
	};

	public List<VarietyVo> getVarietyList() {
		for (int i = 0; i < C._varietyVoList.size(); i++) {
			VarietyVo varietyVo = C._varietyVoList.get(i);
			HTML html = (HTML) this.tableVariety.getWidget(i, 0);
			Integer num = 0;
			try {
				num = (Integer) Integer.parseInt(html.getHTML());
			} catch (Exception ex) {
			}
			varietyVo.varietyId = num;
			TextBox textBox = (TextBox) this.tableVariety.getWidget(i, 1);
			varietyVo.varietyName = textBox.getText();
		}
		return C._varietyVoList;
	}

	public int columnPerRow = 8;

	public AsyncCallback<List<RegionVo>> regionListCallback = new AsyncCallback<List<RegionVo>>() {
		public void onSuccess(List<RegionVo> regionVoList) {
			C._regionVoList = regionVoList;

			HTML html;
			TextBox textBox;
			ListBox listBox;
			tableRowRemove(tableRegion);
			for (int i = 0; i < C._regionVoList.size(); i++) {
				RegionVo regionVo = C._regionVoList.get(i);

				html = new HTML(regionVo.regionId + "");
				html.setWidth(tableRegionHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableRegion.setWidget(i, 0, html);

				textBox = newTextBox(regionVo.regionName, 200);
				textBox.setWidth(getWidth(tableRegionHeader.getWidget(0, 1)) - 6 + "px");
				tableRegion.setWidget(i, 1, textBox);

				textBox = newTextBox(regionVo.toStringRead(regionVo.postCodes, ";"), 200);
				textBox.setWidth(getWidth(tableRegionHeader.getWidget(0, 2)) - 6 + "px");
				tableRegion.setWidget(i, 2, textBox);

				textBox = newTextBox(regionVo.toStringRead(regionVo.subRegions, ";"), 200);
				textBox.setWidth(getWidth(tableRegionHeader.getWidget(0, 3)) - 6 + "px");
				tableRegion.setWidget(i, 3, textBox);

				listBox = new ListBox();
				listBox.addItem("", "");
				for (int j = 0; j < C._stateVoList.size(); j++) {
					StateVo state = C._stateVoList.get(j);
					listBox.addItem(state.stateName, state.stateName);
				}
				setListboxSelected(listBox, regionVo.state);
				listBox.setWidth(tableRegionHeader.getWidget(0, 4).getElement().getStyle().getWidth());
				tableRegion.setWidget(i, 4, listBox);

				html = new HTML("<img src='image/remove.png' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						if (!Window.confirm("remove this record?")) return;
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						RegionVo regionVo = C._regionVoList.get(index);
						C.adminViewS.viewRegionRemove(regionVo.regionId, regionListCallback);
					}
				});
				html.setWidth(tableRegionHeader.getWidget(0, 5).getElement().getStyle().getWidth());
				tableRegion.setWidget(i, 5, html);
			}

			for (int i = 0; i < C._stateVoList.size(); i++) {
				StateVo stateVo = C._stateVoList.get(i);
				int row = 0;
				int column = i;
				RadioButton rad = new RadioButton("radRegionSelect", stateVo.stateName);
				rad.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						RadioButton _rad = (RadioButton) event.getSource();
						String state = _rad.getText();
						for (int i = 0; i < C._regionVoList.size(); i++) {
							RegionVo regionVo = C._regionVoList.get(i);
							int row = 1 + i / columnPerRow;
							int column = i % columnPerRow;
							CheckBox checkBox = (CheckBox) tableRegionSelect.getWidget(row, column);
							if (state.equals(regionVo.state)) {
								checkBox.setValue(true);
							} else {
								checkBox.setValue(false);
							}
						}
					}
				});
				rad.setWidth("300px");
				tableRegionSelect.setWidget(row, column, rad);
			}

			for (int i = 0; i < C._regionVoList.size(); i++) {
				RegionVo regionVo = C._regionVoList.get(i);
				int row = 1 + i / columnPerRow;
				int column = i % columnPerRow;
				CheckBox checkBox = new CheckBox();
				checkBox.setWidth("300px");
				checkBox.setText(regionVo.regionName);
				checkBox.setName(regionVo.regionId + "");
				checkBox.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						for (int i = 0; i < C._stateVoList.size(); i++) {
							int row = 0;
							int column = i;
							RadioButton radioButton = (RadioButton) tableRegionSelect.getWidget(row, column);
							radioButton.setValue(false);
						}
					}
				});
				tableRegionSelect.setWidget(row, column, checkBox);
			}
		}

		public void onFailure(Throwable caught) {
		}
	};

	public AsyncCallback<List<LookupTVo>> lookupTListCallback = new AsyncCallback<List<LookupTVo>>() {
		public void onSuccess(List<LookupTVo> lookupTVoList) {
			C._lookupTVoList = lookupTVoList;

			TextBox textBox;
			ListBox listBox;
			tableRowRemove(tableLookupT);
			for (int i = 0; i < C._lookupTVoList.size() + 20; i++) {
				LookupTVo lookupTVo = null;
				if (i < C._lookupTVoList.size()) lookupTVo = C._lookupTVoList.get(i);

				listBox = new ListBox();
				listBox.addItem("(default)", "0");
				for (int j = 0; j < C._regionVoList.size(); j++) {
					RegionVo region = C._regionVoList.get(j);
					listBox.addItem(region.regionName, region.regionId + "");
				}
				if (lookupTVo != null) setListboxSelected(listBox, lookupTVo.regionId);
				listBox.setWidth(tableLookupTHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableLookupT.setWidget(i, 0, listBox);

				listBox = new ListBox();
				listBox.addItem("", "");
				for (int j = 0; j < C._varietyVoList.size(); j++) {
					VarietyVo variety = C._varietyVoList.get(j);
					listBox.addItem(variety.varietyName, variety.varietyId + "");
				}
				if (lookupTVo != null) setListboxSelected(listBox, lookupTVo.varietyId);
				listBox.setWidth(tableLookupTHeader.getWidget(0, 1).getElement().getStyle().getWidth());
				tableLookupT.setWidget(i, 1, listBox);

				textBox = newTextBox("", 50);
				if (lookupTVo != null) textBox.setText(lookupTVo.heat + "");
				textBox.setWidth(getWidth(tableLookupTHeader.getWidget(0, 2)) - 6 + "px");
				tableLookupT.setWidget(i, 2, textBox);
			}
		}

		public void onFailure(Throwable caught) {
		}
	};

	public AsyncCallback<String> temperatureCallback = new AsyncCallback<String>() {
		public void onSuccess(String html) {
			htmlTemperature.setHTML(html);
		}

		public void onFailure(Throwable caught) {
		}
	};

	public List<RegionVo> getRegionList() {
		for (int i = 0; i < C._regionVoList.size(); i++) {
			RegionVo regionVo = C._regionVoList.get(i);
			HTML html = (HTML) this.tableRegion.getWidget(i, 0);
			Integer num = 0;
			try {
				num = (Integer) Integer.parseInt(html.getHTML());
			} catch (Exception ex) {
			}
			regionVo.regionId = num;
			TextBox textBox = (TextBox) this.tableRegion.getWidget(i, 1);
			regionVo.regionName = textBox.getText();
			textBox = (TextBox) this.tableRegion.getWidget(i, 2);
			regionVo.postCodes = regionVo.toStringList(textBox.getText().trim(), ";");
			textBox = (TextBox) this.tableRegion.getWidget(i, 3);
			regionVo.subRegions = regionVo.toStringList(textBox.getText().trim(), ";");
			ListBox listBox = (ListBox) this.tableRegion.getWidget(i, 4);
			regionVo.state = listBox.getValue(listBox.getSelectedIndex());
		}
		return C._regionVoList;
	}

	public List<FlowerVo> getFlowerList() {
		List<FlowerVo> flowerList = new ArrayList<FlowerVo>();
		int row = this.tableFlower.getRowCount() / 2;
		ListBox listBox;
		TextBox textBox;
		for (int i = 0; i < row; i++) {
			FlowerVo flower = new FlowerVo();
			//public Integer flowerId;
			flower.flowerYear = C._flowerYear;
			flower.memberId = C._memberVo.memberId;

			listBox = (ListBox) this.tableFlower.getWidget(2 * i + 0, 0);
			flower.contact = this.getListboxValue(listBox);
			textBox = (TextBox) this.tableFlower.getWidget(2 * i + 1, 0);
			flower.block = textBox.getText();

			listBox = (ListBox) this.tableFlower.getWidget(2 * i + 0, 1);
			flower.regionId = this.getListboxInteger(listBox);
			listBox = (ListBox) this.tableFlower.getWidget(2 * i + 1, 1);
			flower.subRegion = this.getListboxValue(listBox);

			listBox = (ListBox) this.tableFlower.getWidget(2 * i + 0, 2);
			flower.varietyId = this.getListboxInteger(listBox);
			if (flower.varietyId == null) continue;
			textBox = (TextBox) this.tableFlower.getWidget(2 * i + 1, 2);
			try {
				flower.tree = Integer.parseInt(textBox.getText());
			} catch (Exception ex) {
				flower.tree = 0;
			}

			List<String> endFlowerDateList = C.getEndFlowerDateList("dd-MMM-yyyy");
			flower.dateList = flower.setStringList(flower.dateList, endFlowerDateList);

			List<String> percentList = new ArrayList<String>();
			for (int j = 0; j < C._memberPropertyVo.columns; j++) {
				textBox = (TextBox) tableFlower.getWidget(2 * i + 0, 4 + j);
				String percent;
				try {
					percent = Integer.parseInt(textBox.getText()) + "";
				} catch (Exception ex) {
					percent = "";
				}
				percentList.add(percent);
			}
			flower.percentList = flower.setStringList(flower.percentList, percentList);

			flowerList.add(flower);
		}
		C._memberVo.flowerList = flowerList;

		return C._memberVo.flowerList;
	}

	public List<LookupTVo> getLookupTList() {
		List<LookupTVo> lookupTList = new ArrayList<LookupTVo>();
		int row = this.tableLookupT.getRowCount();
		ListBox listBox;
		TextBox textBox;
		for (int i = 0; i < row; i++) {
			LookupTVo lookupT = new LookupTVo();

			listBox = (ListBox) this.tableLookupT.getWidget(i, 0);
			try {
				lookupT.regionId = Integer.parseInt(this.getListboxValue(listBox));
			} catch (Exception ex) {
				lookupT.regionId = null;
			}

			listBox = (ListBox) this.tableLookupT.getWidget(i, 1);
			try {
				lookupT.varietyId = Integer.parseInt(this.getListboxValue(listBox));
			} catch (Exception ex) {
				lookupT.varietyId = null;
			}

			textBox = (TextBox) this.tableLookupT.getWidget(i, 2);
			try {
				lookupT.heat = Integer.parseInt(textBox.getText());
			} catch (Exception ex) {
				lookupT.heat = 0;
			}
			if (lookupT.regionId != null && lookupT.varietyId != null) lookupTList.add(lookupT);
		}
		C._lookupTVoList = lookupTList;

		return C._lookupTVoList;
	}

	public void setTemperatureUrlMap() {
		ListBox listBox;
		TextBox textBox;
		listBox = (ListBox) this.tableTemperatureHeader.getWidget(1, 0);
		listBox.clear();
		listBox.addItem("", "");
		for (int i = 0; i < C._regionVoList.size(); i++) {
			RegionVo region = C._regionVoList.get(i);
			listBox.addItem(region.regionName, region.regionId + "");

		}
	}

	public TemperatureUrlVo getTemperatureUrlVo() {
		ListBox listBox = (ListBox) this.tableTemperatureHeader.getWidget(1, 0);
		TextBox textBox;
		TemperatureUrlVo temperatureUrlVo = new TemperatureUrlVo();
		temperatureUrlVo.regionId = Integer.parseInt(listBox.getValue(listBox.getSelectedIndex()));
		textBox = (TextBox) tableTemperatureHeader.getWidget(1, 1);
		temperatureUrlVo.minUrl = textBox.getText();
		textBox = (TextBox) tableTemperatureHeader.getWidget(1, 2);
		temperatureUrlVo.maxUrl = textBox.getText();
		C._temperatureUrlVoMap.put(temperatureUrlVo.regionId + "", temperatureUrlVo);
		return temperatureUrlVo;
	}

	public void setFlowerList(List<FlowerVo> flowerList) {
		ListBox listBox;
		TextBox textBox;

		int k = 0;
		for (int i = 0; i < flowerList.size(); i++) {
			FlowerVo flower = flowerList.get(i);
			//public Integer flowerId;
			//flower.flowerYear = C._flowerYear;
			//flower.memberId = C._memberVo.memberId;

			if (!C._memberVo.memberId.equals(flower.memberId)) continue;

			listBox = (ListBox) this.tableFlower.getWidget(2 * k + 0, 0);
			this.setListboxSelected(listBox, flower.contact);
			textBox = (TextBox) this.tableFlower.getWidget(2 * k + 1, 0);
			textBox.setText(flower.block);

			listBox = (ListBox) this.tableFlower.getWidget(2 * k + 0, 1);
			this.setListboxSelected(listBox, flower.regionId);
			ChangeEvent.fireNativeEvent(Document.get().createChangeEvent(), listBox);

			listBox = (ListBox) this.tableFlower.getWidget(2 * k + 1, 1);
			this.setListboxSelected(listBox, flower.subRegion);

			listBox = (ListBox) this.tableFlower.getWidget(2 * k + 0, 2);
			this.setListboxSelected(listBox, flower.varietyId);
			textBox = (TextBox) this.tableFlower.getWidget(2 * k + 1, 2);
			textBox.setText(flower.tree + "");

			//List<String> endFlowerDateList = C.getEndFlowerDateList();
			//flower.dateList = flower.setStringList(flower.dateList, endFlowerDateList);

			List<String> percentList = flower.getStringList(flower.percentList);
			for (int j = 0; j < C._memberPropertyVo.columns; j++) {
				textBox = (TextBox) tableFlower.getWidget(2 * k + 0, 4 + j);
				if (j < percentList.size()) {
					String percent = percentList.get(j);
					textBox.setText(percent);
				}
			}
			k++;
		}

		Collections.sort(flowerList, new Comparator<FlowerVo>() {
			public int compare(FlowerVo o1, FlowerVo o2) {
				if (!o1.regionId.equals(o2.regionId)) return o1.regionId.compareTo(o2.regionId);
				else if (!o1.varietyId.equals(o2.varietyId)) return o1.varietyId.compareTo(o2.varietyId);
				else return o1.flowerId.compareTo(o2.flowerId);
			}

		});

		Map<String, String> regionMap = C.getRegionMap();
		Map<String, String> varietyMap = C.getVarietyMap();
		HTML html;
		for (int i = 0; i < flowerList.size(); i++) {
			FlowerVo flower = flowerList.get(i);
			//public Integer flowerId;
			//flower.flowerYear = C._flowerYear;
			//flower.memberId = C._memberVo.memberId;

			//if (!C._memberVo.memberId.equals(flower.memberId)) continue;

			html = (HTML) this.tableSummary.getWidget(2 * i + 0, 0);
			html.setText(flower.contact);
			html = (HTML) this.tableSummary.getWidget(2 * i + 1, 0);
			html.setText(flower.block);

			html = (HTML) this.tableSummary.getWidget(2 * i + 0, 1);
			html.setText(regionMap.get(flower.regionId + ""));

			html = (HTML) this.tableSummary.getWidget(2 * i + 1, 1);
			html.setText(flower.subRegion);

			html = (HTML) this.tableSummary.getWidget(2 * i + 0, 2);
			html.setText(varietyMap.get(flower.varietyId + ""));

			html = (HTML) this.tableSummary.getWidget(2 * i + 1, 2);
			html.setText(flower.tree + "");

			//List<String> endFlowerDateList = C.getEndFlowerDateList();
			//flower.dateList = flower.setStringList(flower.dateList, endFlowerDateList);

			List<String> percentList = flower.getPercentStringList();
			List<Integer> percentNumList = flower.getTreeNumList();
			for (int j = 0; j < C._memberPropertyVo.columns; j++) {
				if (j < percentList.size()) {
					String percent = percentList.get(j);
					if ("".equals(percent)) continue;
					html = (HTML) tableSummary.getWidget(2 * i + 0, 4 + j);
					html.setHTML(percent);

					html = (HTML) tableSummary.getWidget(2 * i + 1, 4 + j);
					html.setHTML("<b style='color:red'>" + percentNumList.get(j) + "<b/>");
				}
			}
		}

		C._memberVo.flowerList = flowerList;
	}

	public List<String> getRegionSelectIdList() {
		List<String> regionSelectIdList = new ArrayList<String>();
		for (int i = 0; i < C._regionVoList.size(); i++) {
			RegionVo regionVo = C._regionVoList.get(i);
			int row = 1 + i / columnPerRow;
			int column = i % columnPerRow;
			CheckBox checkBox = (CheckBox) tableRegionSelect.getWidget(row, column);
			if (checkBox.getValue() == true) {
				regionSelectIdList.add(regionVo.regionId + "");
			}
		}
		return regionSelectIdList;
	}

	public Map<String, String> getRegionSelectMap() {
		Map<String, String> regionSelectIdMap = new HashMap<String, String>();
		for (int i = 0; i < C._regionVoList.size(); i++) {
			RegionVo regionVo = C._regionVoList.get(i);
			int row = 1 + i / columnPerRow;
			int column = i % columnPerRow;
			CheckBox checkBox = (CheckBox) tableRegionSelect.getWidget(row, column);
			if (checkBox.getValue() == true) {
				regionSelectIdMap.put(regionVo.regionId + "", regionVo.regionName);
			}
		}
		return regionSelectIdMap;
	}

	public String[] colorArray = { "#FF0000", "#00FF00", "#0000FF", "#008080", "#800000", "#800080", "#808000", "#00FFFF", "#000080", "#FF00FF", "#FFFF00" };

	public void setHelp() {
		String html = "<b>List of email variables :</b><br/><br/>";

		html += "${member.memberId}<br/>";
		html += "${member.businessName}<br/>";
		html += "${member.abn}<br/>";
		html += "${member.businessType}<br/>";
		html += "${member.other}<br/>";
		html += "${member.membershipType}<br/>";
		html += "${member.financialMember}<br/>";
		html += "${member.annualReport}<br/>";
		html += "${member.authorisedContact}<br/>";
		html += "${member.marketingGroupUsed}<br/>";
		html += "${member.packsOwnProduce}<br/>";
		html += "${member.marketGroup}<br/>";
		html += "${member.brand}<br/>";
		html += "${member.status}<br/><br/>";

		html += "${contact.contactId}<br/>";
		html += "${contact.memberId}<br/>";
		html += "${contact.firstname}<br/>";
		html += "${contact.surname}<br/>";
		html += "${contact.BHPhone}<br/>";
		html += "${contact.AHPhone}<br/>";
		html += "${contact.fax}<br/>";
		html += "${contact.identifier}<br/>";
		html += "${contact.mobile}<br/>";
		html += "${contact.email}<br/>";
		html += "${contact.service}<br/>";
		html += "${contact.businessStreet}<br/>";
		html += "${contact.businessCity}<br/>";
		html += "${contact.businessState}<br/>";
		html += "${contact.businessCountry}<br/>";
		html += "${contact.businessPostCode}<br/>";
		html += "${contact.postalStreet}<br/>";
		html += "${contact.postalCity}<br/>";
		html += "${contact.postalState}<br/>";
		html += "${contact.postalCountry}<br/>";
		html += "${contact.postalPostCode}<br/>";
		html += "${contact.mailMemberId}<br/>";
		html += "${contact.mailContactId}<br/>";
		html += "${contact.emailFaxContactId}<br/>";
		html += "${contact.status}<br/><br/>";

		html += "${orchard.orchardId}<br/>";
		html += "${orchard.memberId}<br/>";
		html += "${orchard.physicalLocation}<br/>";
		html += "${orchard.postCode}<br/>";
		html += "${orchard.state}<br/>";
		html += "${orchard.emailContactId}<br/>";
		html += "${orchard.status}<br/><br/>";

		this.htmlHelp.setHTML(html);
	}

	public native void previewEmailEditor(String $html) /*-{
		var $previewEditor = $wnd.open("previewEmailEditor.html",
				"previewEmailEditor", "width=1000px,height=800px,scrollbars=1");
		$previewEditor.onload = function() {
			$previewEditor.document.body.innerHTML = $html;
			$previewEditor.focus();
		}
	}-*/;

	public native void previewSmsEditor(String $html) /*-{
		var $previewEditor = $wnd.open("", "previewSmsEditor",
				"width=250px,height=300px,scrollbars=1");
		$previewEditor.document.body.innerHTML = "<pre>" + $html + "</pre>";
		$previewEditor.focus();
	}-*/;
}
